package com.chuanyang.driverh.mainhome.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.TextView;

import com.chuanyang.driverh.R;
import com.chuanyang.driverh.base.BaseListAdapter;
import com.chuanyang.driverh.responseresult.QualifyData;
import com.chuanyang.driverh.utils.BitmapUtil;
import com.chuanyang.driverh.utils.StringUtil;

/**
 * Created by xupeixian on 2017/2/27.
 */

public   class QualifyListAdapter extends BaseListAdapter {

    private ViewHolder viewHolder;

    public QualifyListAdapter(Context context) {
        super(context);
    }

    @Override
    public View getZkView(final int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = getInflater().inflate(R.layout.home_item_qualify, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.iv_qualify_image = (ImageView) convertView.findViewById(R.id.iv_qualify_image);
            viewHolder.rb_stars = (RatingBar) convertView.findViewById(R.id.rb_stars);
            viewHolder.tv_qualify_name = (TextView) convertView.findViewById(R.id.tv_qualify_name);
            viewHolder.tv_qualify_staadd = (TextView) convertView.findViewById(R.id.tv_qualify_staadd);
            viewHolder.tv_qualify_endadd = (TextView) convertView.findViewById(R.id.tv_qualify_endadd);
            viewHolder.tv_qualify_tradetype = (TextView) convertView.findViewById(R.id.tv_qualify_tradetype);
            viewHolder.tv_qualify_aborttime = (TextView) convertView.findViewById(R.id.tv_qualify_aborttime);
            viewHolder.tv_qualify_goodname = (TextView) convertView.findViewById(R.id.tv_qualify_goodname);
            viewHolder.tv_qualify_goodweight = (TextView) convertView.findViewById(R.id.tv_qualify_goodweight);
            viewHolder.tv_qualify_baseprice = (TextView) convertView.findViewById(R.id.tv_qualify_baseprice);
            viewHolder.tv_delete = (TextView) convertView.findViewById(R.id.tv_delete);
            viewHolder.ll_qualify_div = (LinearLayout) convertView.findViewById(R.id.ll_qualify_div);
            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        QualifyData.DataBean bean = (QualifyData.DataBean) getItem(position);
        BitmapUtil.showImgForNetPath( bean.getUserImage(),viewHolder.iv_qualify_image);
        viewHolder.tv_qualify_name.setText(bean.getUsername());
        viewHolder.rb_stars.setRating(bean.getUserStar());
        viewHolder.tv_qualify_staadd.setText(bean.getStartCity());
        viewHolder.tv_qualify_endadd.setText(bean.getTargetCity());

        if (bean.getCurrency() == 2) {
            viewHolder.tv_qualify_tradetype.setVisibility(View.VISIBLE);
            if (!TextUtils.isEmpty(bean.getMinPrice())) {
                viewHolder.tv_qualify_baseprice.setText("最低价: " + StringUtil.getDouble(bean.getMinPrice()+"")+ "$/t");
            } else {
                viewHolder.tv_qualify_baseprice.setText("");

            }
        } else {
            viewHolder.tv_qualify_tradetype.setVisibility(View.GONE);
            if (!TextUtils.isEmpty(bean.getMinPrice())) {
                viewHolder.tv_qualify_baseprice.setText("最低价: " + StringUtil.getDouble(bean.getMinPrice()+"")+ "¥/t");
            } else {
                viewHolder.tv_qualify_baseprice.setText("");

            }

        }
        viewHolder.tv_qualify_aborttime.setText(bean.getOrder_endtime());
        viewHolder.tv_qualify_goodname.setText(bean.getGoodsName());
        if (bean.getGoodsWeight() != null) {
            viewHolder.tv_qualify_goodweight.setText(bean.getGoodsWeight() + "");
        }
        viewHolder.tv_delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener!=null)
                {
                    listener.onCustomerListener(viewHolder.tv_delete,position);
                }
            }
        });
        viewHolder.ll_qualify_div.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener!=null)
                {
                    listener.onCustomerListener(viewHolder.ll_qualify_div,position);
                }
            }
        });
        return convertView;
    }
    private class ViewHolder {
        private ImageView iv_qualify_image;
        private RatingBar rb_stars;
        private TextView tv_qualify_name;
        private TextView tv_qualify_staadd;
        private TextView tv_qualify_endadd;
        private TextView tv_qualify_tradetype;
        private TextView tv_qualify_aborttime;
        private TextView tv_qualify_goodname;
        private TextView tv_qualify_goodweight;
        private TextView tv_qualify_baseprice;
        private TextView tv_delete;
        private LinearLayout ll_qualify_div;
    }
}


